﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Labirinto_Magico
{
    class GameGuiRender
    {
        RenderingData mRenderWrapper;

        public GameGuiRender(RenderingData iRender, Viewport iViewport)
        {
            mRenderWrapper = iRender;
        }

        void DrawCP(Vector2 iPosition, float iDimension, SI.ORIENTATION iOrientation, bool selected)
        {
            float rotation;
            if (SI.ORIENTATION.W == iOrientation)
                rotation = ((float)Math.PI * 1.5f);
            else if (SI.ORIENTATION.S == iOrientation)
                rotation = ((float)Math.PI);
            else if (SI.ORIENTATION.E == iOrientation)
                rotation = ((float)Math.PI * 0.5f);
            else
                rotation = 0;

            Texture2D tex;
            if (selected)
                tex = mRenderWrapper.mTextureData.arrowSelected;
            else
                tex = mRenderWrapper.mTextureData.arrow;

            Vector2 dim = new Vector2(iDimension, iDimension);

            mRenderWrapper.DrawTexture(tex, dim, iPosition, rotation, Color.White);
        }

        public void DrawCPs(GUICPButton[] iCPs)
        {
            LabyrinthGameState.State iState = LabyrinthGameState.gameState;
            float tileLenght = iCPs[0].mDimension.X;

            if (iState.mFirstPart)
            {
                foreach (GUICPButton b in iCPs)
                {
                    if (b.mType == SI.POSITION.Left)
                        DrawCP(b.mPosition, tileLenght, SI.ORIENTATION.E, b.IsMouseOver());

                    if (b.mType == SI.POSITION.Right)
                        DrawCP(b.mPosition, tileLenght, SI.ORIENTATION.W, b.IsMouseOver());

                    if (b.mType == SI.POSITION.Up)
                        DrawCP(b.mPosition, tileLenght, SI.ORIENTATION.S, b.IsMouseOver());

                    if (b.mType == SI.POSITION.Down)
                        DrawCP(b.mPosition, tileLenght, SI.ORIENTATION.N, b.IsMouseOver());
                }

            }
        }

        public void DrawVictory(Player.Player iWinner, GUITimingLabel iLabel)
        {
            mRenderWrapper.DrawTexture(mRenderWrapper.mTextureData.winnerTexture, iLabel.mDimension, iLabel.mPosition, 0, Color.White);
            mRenderWrapper.DrawFont(mRenderWrapper.mTextureData.victoryFont, iLabel.mPosition, iWinner.ToString() + "\nwins!!!", Color.Black, 1);
        }

        public void DrawNextTurn(Player.Player iNext, GUITimingLabel iLabel)
        {
            mRenderWrapper.DrawTexture(mRenderWrapper.mTextureData.winnerTexture, iLabel.mDimension, iLabel.mPosition, 0, Color.White);
            mRenderWrapper.DrawFont(mRenderWrapper.mTextureData.victoryFont, iLabel.mPosition, iNext.ToString() + "\nis your turn!", Color.Black, 1);
        }

        public void DrawScore(Player.Player iPlayer, GUILabel iLabel)
        {

            mRenderWrapper.DrawTexture(mRenderWrapper.mTextureData.playerScore, iLabel.mDimension, iLabel.mPosition, 0, Color.White);
            mRenderWrapper.DrawFont(mRenderWrapper.mTextureData.scoreFont, iLabel.mPosition, iPlayer.ToString() + "\nGoal: " + iPlayer.mGoalToCatch, Color.Black, 1);
        }

        public void DrawButton(GUIButton iButton)
        {
            if (iButton.IsMouseOver())
                mRenderWrapper.DrawTexture(mRenderWrapper.mTextureData.pauseSelected, iButton.mDimension, iButton.mPosition, 0, Color.White);
            else
                mRenderWrapper.DrawTexture(mRenderWrapper.mTextureData.pause, iButton.mDimension, iButton.mPosition, 0, Color.White);
        }
    }
}
